#ifndef PACKETCAPAPI_H
#define PACKETCAPAPI_H

#include <QLibrary>
#include "pcap/pcap.h"

extern QLibrary g_wpcapDll;
extern QLibrary g_packetDll;

typedef const char *(*api_pcap_lib_version)(void);

typedef int	(*api_pcap_findalldevs_ex)(const char *source,
        struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
typedef void (*api_pcap_freealldevs)(pcap_if_t *);

typedef pcap_t *(*api_pcap_open)(const char *source, int snaplen, int flags,
        int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
typedef void (*api_pcap_close)(pcap_t *);
typedef int	(*api_pcap_loop)(pcap_t *, int, pcap_handler, u_char *);
typedef int	(*api_pcap_sendpacket)(pcap_t *, const u_char *, int);
typedef char *(*api_pcap_geterr)(pcap_t *);

typedef pcap_send_queue *(*api_pcap_sendqueue_alloc)(u_int memsize);
typedef void (*api_pcap_sendqueue_destroy)(pcap_send_queue *queue);
typedef int (*api_pcap_sendqueue_queue)(pcap_send_queue *queue,
        const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
typedef u_int (*api_pcap_sendqueue_transmit)(pcap_t *p, pcap_send_queue *queue, int sync);

#define wpcap_api(api_type) ((api_##api_type)g_wpcapDll.resolve(#api_type))()
#define wpcap_api_arg1(api_type, arg) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg)
#define wpcap_api_arg2(api_type, arg1, arg2) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg1, arg2)
#define wpcap_api_arg3(api_type, arg1, arg2, arg3) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg1, arg2, arg3)
#define wpcap_api_arg4(api_type, arg1, arg2, arg3, arg4) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg1, arg2, arg3, arg4)
#define wpcap_api_arg5(api_type, arg1, arg2, arg3, arg4, arg5) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg1, arg2, arg3, arg4, arg5)
#define wpcap_api_arg6(api_type, arg1, arg2, arg3, arg4, arg5, arg6) ((api_##api_type)g_wpcapDll.resolve(#api_type))(arg1, arg2, arg3, arg4, arg5, arg6)

bool initPCap();

#endif // PACKETCAPAPI_H
